/*
初始化为全都要，从前i本书中考虑不要几本，目标价格为j
*/
#include <cstdio>
#include <algorithm>
using namespace std;
#define DEBUG
// using ll=long long;
inline int read()
{
    int c=getchar(), f=1, x=0;
    if(c=='-') f*=-1, c=getchar();
    while(c<'0'&&'9'<c) c=getchar();
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    return f*x;
}

inline void write(int x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}

const int N=40, M=3e5+10, INF=0x3f3f3f3f;
int n, m, sum;
int a[N];
int f[N][M]; 

void init()
{
    n=read(), m=read();
    for(int i=1; i<=n; i++)
        a[i]=read(), sum+=a[i];
        
}

void solve()
{
    init();
    int ans=INF;
    
    for(int i=1; i<=n; i++) f[i][sum]=sum; //需要达到总价，每本书都要
    for(int j=m; j<=sum; j++) f[0][j]=sum; //每本书都要(从前0本书判断不要)
    //从前i个物品中判断不选，目标价格为j
    for(int i=1; i<=n; i++)
        for(int j=sum; j>=m; j--)
        {
            f[i][j]=f[i-1][j]; //选当前物品
            if(j+a[i]<=sum)
                f[i][j]=min(f[i-1][j+a[i]]-a[i], f[i][j]); //不选当前书，所以前i-1本的价格就需要达到j+a[i],再不选当前这本
            ans=min(ans, f[i][j]);
        }
    write(ans); puts("");
} 

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif

    int T=1; //cin >> T; 
    while(T--) 
    {
        solve();
    }
    return 0;
}